<?php
require_once('../libraryfiles/config.php');

	
$action = isset($_GET['action']) ? $_GET['action'] : '';

switch($action)
{
	case 'save':
		save();
		break;	
		
	case 'send':
		save(true);
		break;				
	
	case 'delselected':		
		delselected();
		break;
		
	default :
	    // if action is not defined or unknown
		// move to main user page
		header('Location: index.php');
		exit();
}

function save($send=false){
	$pio_id = $_POST['hidepio_id'];	
	$oip_id = $_POST['hideoip_id'];
	$unique_price = $_POST['txtuniquep'];
	$price = $_POST['txtprice'];
	
	foreach($pio_id as $key => $value){
		$pioId = $value;
		$oipId = $oip_id[$key];
		$uniquePrice = $unique_price[$key];
		$newprice = $price[$key];
		
		$sql = "UPDATE tblpro_order_in_pharmacy SET unique_price = '$uniquePrice', price = '$newprice' WHERE pio_id = $pioId AND oip_id = $oipId";
		mysql_query($sql);
	}
	
	if($send){
		$order_id = $_POST['hideorder_id'];	
		$pharma_id = $_SESSION['acc_id'];
		$total_price = $_POST['txttotal'];
		$sql_u = "UPDATE tblordernance_in_pharmacy SET pharma_check = 1, reply_date = NOW(), total_price = '$total_price' WHERE ordernance_id = $order_id AND pharmacy_id = $pharma_id";
		mysql_query($sql_u);
	}
	
	header("Location: viewprescription.php");
	exit;
}

function delselected(){
	if(isset($_POST['id'])){
		
		//Statement to get selected id
		$id = (is_array($_POST['id']))?implode(',',$_POST['id']):$_POST['id'];
		
		$sql = "UPDATE tblordernance_in_pharmacy SET isDeleted = 1 WHERE id IN ($id)";
		mysql_query($sql);
	}
	
	header('Location: viewprescription.php?'.getAllGetParams(array('view','action')));  //.'&page='.$page
	exit();	
}
?>